float4x4 World;
float4x4 View;
float4x4 Projection;
float4x4 WVP;

float3 LightPos;
float3 AmbientColor;
float3 DiffuseColor;

float2 offXY = float2(0.0f,0.0f);

texture tbase0;
texture tbase1;
texture tbase2;
texture tbase3;
 
 float2 chunk_size = float2(64,64);

sampler sampl0 = sampler_state
{
  texture = <tbase0>;
  mipfilter = LINEAR;
};

sampler sampl1 = sampler_state
{
  texture = <tbase1>;
  mipfilter = LINEAR;
};

sampler sampl2 = sampler_state
{
  texture = <tbase2>;
  mipfilter = LINEAR;
};

sampler sampl3 = sampler_state
{
  texture = <tbase3>;
  mipfilter = LINEAR;
};



//--------------------------------------------------------------------------------------
// Vertex shader
//--------------------------------------------------------------------------------------
struct VS_IN
{
	float3 pos	:POSITION;
};
struct VS_OUT
{
	float4 pos	:POSITION;
	float2 uv	:TEXCOORD0;
	float2 uv1	:TEXCOORD1;
};

VS_OUT RenderVS( VS_IN In )
{
	VS_OUT Out;
	
	In.pos.xz += offXY.xy;
	
	float2 tuv = float2(In.pos.x/512, In.pos.z/512);
	
	float4 td = tex2Dlod(sampl0, float4(tuv,0,1));
	
	Out.uv1.x = In.pos.x/16;
	Out.uv1.y = In.pos.z/16;
	Out.uv.x = In.pos.x/512;
	Out.uv.y = In.pos.z/512;
	
	In.pos.y = 0.0f;
	
	//In.pos.xz -=256;
	Out.pos = mul(float4(In.pos,1), WVP); 
	return Out;
};

//------------------------------------------------------------------

//--------------------------------------------------------------------------------------
// Pixel shader
//--------------------------------------------------------------------------------------
struct PS_IN
{
	float2 uv	:TEXCOORD0;
	float2 uv1	:TEXCOORD0;
};
float4 RenderPS( PS_IN In ) : COLOR0
{
	float4 color0  = tex2D(sampl1, In.uv1);
	float4 color1  = tex2D(sampl2, In.uv);
	float4 color2  = tex2D(sampl3, In.uv);
 
	float4 outColor =  color1 ;

	outColor.a = 1;
	return outColor;
}

technique FirstTechnique
{
    pass FirstPass
    {
        Lighting = TRUE;
        ZEnable = TRUE;

        VertexShader = compile vs_3_0 RenderVS();
        PixelShader =  compile ps_3_0 RenderPS();
    }
}